package com.pubinfo.passbook.common.service.master.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pubinfo.passbook.common.entity.TRuleCity;
import com.pubinfo.passbook.common.mapper.TRuleDistrictMapper;
import com.pubinfo.passbook.common.mapper.TRuleGenusMapper;
import com.pubinfo.passbook.common.mapper.TRuleParamMapper;
import com.pubinfo.passbook.common.model.dto.rule.RuleCityParam;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.rule.CityIdRelevanceVo;
import com.pubinfo.passbook.common.service.master.TRuleCityService;
import com.pubinfo.passbook.common.mapper.TRuleCityMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 *
 */
@Service
@Slf4j
public class TRuleCityServiceImpl extends ServiceImpl<TRuleCityMapper, TRuleCity>
    implements TRuleCityService {
  
  @Override
  public IPage<TRuleCity> selectRuleCity(RuleCityParam param) {
    IPage<TRuleCity> iPage = page(param.getPage("create_time"));
    return this.baseMapper.selectRuleCity(iPage, param);
  }
  
  @Override
  public JsonResult<String> removeRuleCity(String cityId) {
    List<CityIdRelevanceVo> relevanceVoList = this.baseMapper.selectCityIdRelevance(cityId);
    relevanceVoList.removeIf(Objects::isNull);
    if (!relevanceVoList.isEmpty())
      return JsonResult.error("数据被其他表引用，删除失败");
    int result = this.baseMapper.deleteById(cityId);
    return result > 0 ? JsonResult.success("删除成功") : JsonResult.error("删除失败");
  }
}




